
<article class="help">
  <carousel class="deck container-fluid">
    <slide class="row-fluid summary">
      <div class="summary col-sm-3">
        <h3>Query Plan</h3>
        <p class="lead">Understand what cypher is doing</p>
      </div>
      <div class="details col-sm-5">
        <p>Cypher breaks down the work of executing a query into small pieces called&nbsp;<em>operators</em>. Each operator is responsible for a small part of the overall query.
          The operators are connected together in a pattern called a Query Plan.
        </p>
        <p>When you use the&nbsp;<a help-topic="explain">EXPLAIN</a> or&nbsp;<a help-topic="profile">PROFILE</a> commands, Neo4j Browser displays a diagram of the Query Plan.</p>
        <p>
          Click the right arrow button for the later pages of this guide,
          which explain how to read the Query Plan diagram.
        </p>
      </div>
      <div class="details col-sm-4"><img src="images/query-plan.svg" class="img-responsive pull-right"/></div>
    </slide>
    <slide class="row-fluid">
      <div class="details col-sm-5"><img src="images/query-plan-operator-rows.svg" class="img-responsive"/></div>
      <div class="details col-sm-7">
        <h4>Operators</h4>
        <p>
          Each Operator is displayed as a rectangle with its name in
          the top-left corner. See the&nbsp;<a target="_blank" href="https://neo4j.com/docs/developer-manual/cypher/execution-plans/">operators manual page</a> for a description of what each operator does.
        </p>
        <h4>Pipes</h4>
        <p>
          Operators are connected by pipes; each pipe represents the output of
          one operator and the input of the next.
        </p>
        <h4>Rows</h4>
        <p>
          In Query Plan diagrams, the width of a pipe indicates the number
          of rows that pass between operators. This means that by looking at the
          overall diagram, you can quickly see the&nbsp;<em>shape</em> of the query, in terms of which parts process lots of rows,
          and which parts process few.
        </p>
        <h4>Estimated rows</h4>
        <p>When you use the&nbsp;<a help-topic="explain">EXPLAIN</a> keyword, the query is not actually executed; so it's not possible to show actual number
          of rows for each pipe. In this case, the Query Plan diagram shows&nbsp;<em>estimated rows</em> instead. These numbers are predicted based on Neo4j's built-in
          statistics. The Cypher cost-based planner uses estimated rows to determine
          the optimal query plan.
        </p>
      </div>
    </slide>
    <slide class="row-fluid">
      <div class="details col-sm-5"><img src="images/query-plan-operator-cost.svg" class="img-responsive"/></div>
      <div class="details col-sm-7">
        <h4>Database hits</h4>
        <p>
          Each operator will ask the Neo4j storage engine to do work such as retrieving or updating data.
          A&nbsp;<em>database hit</em> is an abstract unit of this storage engine work.
        </p>
        <p>When you use the&nbsp;<a help-topic="profile">PROFILE</a>command, the footer of the result frame displays the total number of database hits incurred
          while running the query.
          By comparing this total for different query plans, you can tell which one is better
          in terms of work for the storage engine.
        </p>
        <p>
          In addition of the total number of database hits, the Query Plan diagram shows
          the database hits for each individual operator. For operators with a large number
          of database hits, there is a red box underneath the operator, with its height
          proportional to the number.  This means that you can glance very quickly at the whole
          Query Plan diagram and spot the operators that are responsible for significant storage engine work.
        </p>
      </div>
    </slide>
    <slide class="row-fluid">
      <div class="details col-sm-5"><img src="images/query-plan-operator-details.svg" class="img-responsive"/></div>
      <div class="details col-sm-7">
        <h4>Click to expand</h4>
        <p>
          Some operators can reveal more information about what they are doing.
          If you see a triangular expand icon next to the operator name,
          you can click to expand the operator and reveal some more details.
          When you're done, you can click the header again to collapse the operator
          and hide the details.
        </p>
        <p>If you want to quickly expand all the operators, there are expand-all&nbsp;<i class="fa fa-caret-square-o-down"></i> and collapse-all&nbsp;<i class="fa fa-caret-square-o-up"></i> buttons below the diagram.</p>
        <h4>Identifiers</h4>
        <p>
          The first section of details lists the identifiers that the operator works with.
          if you've named identifers in your query, e.g.&nbsp;<code>MATCH (n)</code> then you should find the identifier n bound in one of the operators.
          In addition to identifiers that you named in your query you may see
          some internal identifiers that Cypher has introduced to keep track
          of unnamed entities.
        </p>
        <h4>Expressions</h4>
        <p>
          After the identifiers, you'll see a section for an expression.
          This is commonly a boolean expression such as&nbsp;<code>hasProp(born)</code> or it can be a graph pattern to be expanded such as&nbsp;<code>()-[r]-()</code>
        </p>
        <p>
          <table class="table-condensed table-help">
            <tr>
              <th>Reference:</th>
              <td><code><a target="_blank" href="https://neo4j.com/docs/developer-manual/3.2/cypher/execution-plans/">Execution Plans</a></code> manual page</td>
            </tr>
            <tr>
              <th>Related:</th>
              <td><a help-topic="explain">:help EXPLAIN</a>&nbsp;<a help-topic="profile">:help PROFILE</a>&nbsp;</td>
            </tr>
          </table>
        </p>
      </div>
    </slide>
  </carousel>
</article>
